#include "object.hpp"

Object::Object(ObjType type):_type(type),_iscolliable(false){}

void Object::SetPosition(int x, int y){
    _oldpos = _position;
    _position.x = x;
    _position.y = y;
}

SDL_Point Object::GetPosition() const{
    return _position;
}

SDL_Point Object::GetOldPos() const{
    return _oldpos;
}

void Object::GoBack(){
    _position = _oldpos;
}

void Object::Move(int offset_x, int offset_y){
    SetPosition(_position.x+offset_x, _position.y+offset_y);
}

void Object::SetColor(SDL_Color color) {
    _color = color;
}

SDL_Color Object::GetColor(){
    return _color;
}

ObjType Object::GetType() const{
    return _type;
}

string Object::GetName() const{
    return string(::GetName(_name));
}

void Object::SetName(Names name){
    _name = name;
}

bool Object::IsCollidable() const{
    return _iscolliable;
}

void Object::Update(){}

void Object::Draw(){
    string c;
    switch(GetType()){
        case ObjType::CREATURE:
            if(_name==Names::CREATURE_PLAYER)
                c = "@";
            else if(_name == Names::CREATURE_WOOD_TARGET)
                c = CURSE_YUAN;
            else if(_name == Names::CREATURE_BUGS)
                c = "a:";
            break;
        case ObjType::WALL:
            if(_name==Names::WALL_VERT)
                c = "|";
            else if(_name==Names::WALL_HORI)
                c = "-";
            break;
        case ObjType::GROUND:
            c = CURSE_SMALL_DOT;
            break;
        case ObjType::WEAPON:
            c = ")";
            break;
        case ObjType::ARMOR:
            c = "[";
            break;
        default:
            c = "U";
    }
    DrawCurse(c, _position.x, _position.y, _color);
}

ostream& operator<<(ostream& o, Object& obj){
    o<<"Object<type:"<<static_cast<int>(obj.GetType())<<", pos("<<obj.GetPosition().x<<","<<obj.GetPosition().y<<")";
    return o;
}
